#CMake版本，务必放在首行
cmake_minimum_required(VERSION 3.0)

#设置编译目标系统，定义系统名称，务必放在获取源文件之前，用来说明当前操作系统。
#只有这个变量被设置了，CMake才认为此时正在交叉编译，会额外设置一个变量CMAKE_CROSSCOMPLING为TRUE
set(CMAKE_SYSTEM_NAME "linux")   
set(CMAKE_SYSTEM_PROCESSOR riscv)

#跳过编译链检测
set(CMAKE_C_COMPILER_FORCED TRUE) # skip compiler test
set(CMAKE_CXX_COMPILER_FORCED TRUE)

set(CMAKE_C_COMPILER "riscv64-unknown-elf-gcc")
set(CMAKE_ASM_COMPILER "riscv64-unknown-elf-gcc")
set(CMAKE_AR "riscv64-unknown-elf-ar")
set(CMAKE_OBJCOPY "riscv64-unknown-elf-objcopy")
set(CMAKE_OBJDUMP "riscv64-unknown-elf-objdump")
set(CMAKE_SIZE "riscv64-unknown-elf-size")

ENABLE_LANGUAGE(ASM)
set(LD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ld) 
set(BIN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin) 

set(LINKER_SCRIPT "${LD_PATH}/link_flash_bs1.lds")
set(RISCV_MARCH rv32imc)
set(ABI ilp32)

set(ARCH_FLAGS "-march=${RISCV_MARCH} -mabi=${ABI} -mcmodel=medlow")
set(LINK_FLAGS "-Wl,-T${LINKER_SCRIPT} ${ARCH_FLAGS} -Wl,--no-relax -Wl,--gc-sections -nostartfiles --specs=nano.specs")
set(C_FLAGS "-Wall -W -g ${ARCH_FLAGS} -Wmaybe-uninitialized -ffunction-sections -fdata-sections -fno-exceptions -fno-builtin-printf -Wno-unused-function -Wno-unused-parameter -Wno-format")

project(rv VERSION 1.0)

add_subdirectory(src)
